package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.BaseManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
//@CrossOrigin
public class BaseManageController {
    @Autowired
    private BaseManageService baseManageService;

    /**
     * 查询一级分类数据
     * @return
     */
    @GetMapping("/getCategory1")
    public Result  getCategory1(){
        List<BaseCategory1> category1=baseManageService.getCategory1();
        return  Result.ok(category1);
    }
    /**
     * 查询二级分类数据
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> category2s=baseManageService.getCategory2(category1Id);
        return  Result.ok(category2s);
    }

    ///admin/product/getCategory3/{category2Id}
    /**
     * 查询三级分类数据
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> category3=baseManageService.getCategory3(category2Id);
        return  Result.ok(category3);
    }

    // /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
    /**
     * 根据分类Id 获取平台属性集合
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id){
        List<BaseAttrInfo> baseAttrInfoList=baseManageService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(baseAttrInfoList);
    }
    /**
     * 保存平台属性
     */
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo ){
            baseManageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    /**
     *根据平台属性Id 获取到平台属性值集合
     */
    // /admin/product/getAttrValueList/{attrId}
    @GetMapping("/getAttrValueList/{attrId}")
    public  Result getAttrValueList(@PathVariable Long attrId){
        //本来可以直接查询AttrValue平台属性值集合
        // select * from base_attr_info  where id = attrId
        //这样更加符合业务  可以从平台上获取平台属性值
      BaseAttrInfo baseAttrInfo=baseManageService.getAttrInfoList(attrId);
        return Result.ok(baseAttrInfo.getAttrValueList());
    }

    // /admin/product/baseSaleAttrList

    /**
     * 获取销售属性数据
     * @return
     */
     @GetMapping("/baseSaleAttrList")
    public Result  getBaseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList=baseManageService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrList);
     }

}
